package cn.edu.scau.cmi.xuchuangxiong.client;

import java.util.Scanner;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import cn.edu.scau.cmi.xuchuangxiong.mybatis.pojo.Student;
import cn.edu.scau.cmi.xuchuangxiong.mybatis.pojo.Teacher;
import cn.edu.scau.cmi.xuchuangxiong.mybatis.service.StudentService;
import cn.edu.scau.cmi.xuchuangxiong.mybatis.service.TutorService;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class SpringClient {
	@Autowired
	StudentService studentService;

	@Autowired
	TutorService tutorService;
	
	@Test
	public void testStudentService() {
		while (true) {
			System.out.println("[1]添加学生\n[2]修改学生\n[3]删除学生\n[4]添加教师\n[5]修改教师\n[6]删除教师");
			System.out.println("[7]学生选择指导教师\n[8]学生修改指导教师\n[9]教师选择被指导学生\n[10]教师修改被指导学生\n[11]展示学生及其导师");
			System.out.println("请输入选择：");
			Scanner sci = new Scanner(System.in);
			Scanner scs = new Scanner(System.in);
			int choice = sci.nextInt();

			if (choice == 1) {
				Student student = new Student();
				System.out.println("请输入添加学生学号：");
				String stuID = scs.nextLine();
				student.setStuID(stuID);
				System.out.println("请输入添加学生姓名：");
				String stuName = scs.nextLine();
				student.setStuName(stuName);
				studentService.inserStudent(student);
				System.out.println("添加成功\n");
			}
			
			else if(choice == 2)
			{
				Student student = new Student();
				System.out.println("请输入修改学生学号：");
				String stuID = scs.nextLine();
				student.setStuID(stuID);
				System.out.println("请输入修改学生姓名：");
				String stuName = scs.nextLine();
				student.setStuName(stuName);
				System.out.println(student);
				studentService.updateStudentName(student);
			}
			
			else if(choice == 3)
			{
				System.out.println("请输入删除学生学号：");
				String stuID = scs.nextLine();
				studentService.deleteStudentByID(stuID);		
			}
			
			else if(choice == 7)
			{
				System.out.println("请输入学生学号：");
				String stuID = scs.nextLine();
				System.out.println("请输入导师工号：");
				String tutorID = scs.nextLine();
				studentService.updateStudentTutorByID(stuID, tutorID);
				tutorService.insertTutor(tutorID, stuID);
				System.out.println("选择成功\n");
			}
			
			else if(choice == 11)
			{
				System.out.println("请输入学生学号：");
				String stuID = scs.nextLine();
				Teacher teacher = studentService.selectStudentTutor(stuID);
				Student student = studentService.getStudentByID(stuID);
				System.out.println("学生姓名：" + student.getStuName() + "，导师姓名：" + teacher.getTeaName());
				System.out.println();
			}
		}

	}

}
